package com.zxf.appliction.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zxf.appliction.dao.ColumnsMapper;
import com.zxf.appliction.dao.FilesupMapper;
import com.zxf.appliction.dao.StaffVoMapper;
import com.zxf.appliction.domain.Columns;
import com.zxf.appliction.domain.Filesup;
import com.zxf.appliction.domain.Params;
import com.zxf.appliction.domain.Staffvo;


@Service  
//默认将类中的所有函数纳入事务管理.  
@Transactional  
public class FileService {
	
	 
	    @Autowired  
	    private ColumnsMapper columnMapper; 
	    
	    @Autowired  
	    private FilesupMapper filesupMapper; 
	    
	    @Autowired  
	    private StaffVoMapper staffVoMapper; 
	  
	 public void insertUser(Columns column) {  
	        //新增用户  
		 columnMapper.insert(column);  
	}

	public Columns getId(int userid) {
		return columnMapper.selectByPrimaryKey(userid);
	}

	public List getUserList() {
		// 用户列表
		return columnMapper.getColumnList();
	}

	public Map getUserList2() {
		Map<String, Object> userMap;
		 userMap=columnMapper.getColumnJson();
		 return userMap;
	}

	public int insertFile(Filesup fileUp) {
		return filesupMapper.insertSelective(fileUp);
		
	}

	

	public int insertAndGetstaffID(Staffvo staffvo) {
		return staffVoMapper.insertAndGetstaffID(staffvo);
	}
//文件列表
	public List getFilelist(Params params) {
		return filesupMapper.getFilelist(params);
	}
//文件数量
	public int getFiletotle() {
		return filesupMapper.getFiletotle();
	}

	public List<Staffvo> getFileListBytop(Integer i) {
		return staffVoMapper.getFileListBytop(i);
	}

	public List<Staffvo> getFileListByPagesizeAndPage(Params params, String searchText) {
		// 开始记录数
				Integer starnum = params.getPagesize() * (params.getPage() - 1);
				Integer endnum = params.getPagesize();

				return staffVoMapper.getFileListByPagesizeAndPage(starnum, endnum, searchText);
	}

	public int getFileTotleByPagesizeAndPage(Params params, String searchText) {
		// 开始记录数
				Integer starnum = params.getPagesize() * (params.getPage() - 1) + 1;
				Integer endnum = starnum + params.getPagesize();

				int totalArticle = staffVoMapper.getFileTotleByPagesizeAndPage(
						starnum, endnum, searchText);
				int totalPages = 0;
				if (totalArticle % params.getPagesize() != 0) {
					totalPages = totalArticle / params.getPagesize() + 1;
				} else {
					totalPages = totalArticle / params.getPagesize();
				}
				return totalPages;
	}

	/**
	 * 
	 * @param staffid
	 * @return
	 */
	public Staffvo detailstaffvo(Integer staffid) {
		return staffVoMapper.selectByPrimaryKey(staffid);
	}

	/**
	 * 
	 * @param staffid
	 * @return
	 */
	public List<Filesup> getfilesupListByStaffid(Integer staffid) {
		return filesupMapper.getfilesupListByStaffid(staffid);
	}
	
	/**
	 * 
	 * @param staffVo
	 */
	public void insertStaffVo(Staffvo staffVo) {
		staffVoMapper.insertSelective(staffVo);
		
	}

	/**
	 * staffname 通过查询staffid
	 * @param staffname
	 * @return
	 */
	public Integer getStaffidByStaffname(String staffname) {
		return staffVoMapper.getStaffidByStaffname(staffname);
	}
}
